<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/taglib.jsp" %>
<!-- Modal -->
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title"><c:if test="${empty rank.id}">增加</c:if><c:if test="${not empty rank.id}">修改</c:if>记录</h4>
</div>

<div class="modal-body">
    <form id="editForm" class="form-horizontal style-form">
        <input type="hidden" value="${rank.id}" name="id"/>
        <div class="form-group">
            <label class="col-sm-2 control-label">标题</label>
            <div class="col-sm-5">
                <input type="text" name="colName" class="form-control" value="${rank.colName}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">数据源</label>
            <div class="col-sm-10">
                <label>
                    <input type="radio" name="robotFlag" value="0"
                           onclick="checkState(this);"
                           <c:if test="${rank.robotFlag == 0 || create == 1}">checked</c:if>>
                    &nbsp;CMS配置
                </label>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <label>
                    <input type="radio" name="robotFlag" value="1"
                           onclick="checkState(this);"
                           <c:if test="${rank.robotFlag == 1}">checked</c:if>>
                    &nbsp;自动化数据
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">接口标识</label>
            <div class="col-sm-5">
                <input type="text" name="colRankNum"
                       <c:if test="${not empty rank.id}">readonly</c:if>
                       class="form-control" value="${rank.colRankNum}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">副标题</label>
            <div class="col-sm-5">
                <input type="text" name="colSubName" class="form-control" value="${rank.colSubName}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">封面图</label>
            <div class="col-sm-10">
                <input class="form-control" value="${rank.colPoster}" name="colPoster" type="text"
                       onblur="$('#colPosterImg').attr('src', $(this).val());">
                竖图:
                <a href="${rank.colPoster}" target="_blank"><img id="colPosterImg" class="img-thumbnail"
                                                                 src="${rank.colPoster}" height="100"
                                                                 width="100"/></a>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">排行榜展示数</label>
            <div class="col-sm-5">
                <input type="text" name="outsideNum" class="form-control" value="${rank.outsideNum}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">包含内容数</label>
            <div class="col-sm-5">
                <input type="text" name="insideNum" class="form-control" value="${rank.insideNum}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">分类</label>
            <div class="col-sm-10">
                <label>
                    <input type="radio" name="colVideoType" value="1"
                           <c:if test="${rank.colVideoType == 1}">checked</c:if>>
                    &nbsp;电视剧
                </label>
                <label>
                    <input type="radio" name="colVideoType" value="2"
                           <c:if test="${rank.colVideoType == 2}">checked</c:if>>
                    &nbsp;电影
                </label>
                <label>
                    <input type="radio" name="colVideoType" value="3"
                           <c:if test="${rank.colVideoType == 3}">checked</c:if>>
                    &nbsp;动漫
                </label>
                <label>
                    <input type="radio" name="colVideoType" value="4"
                           <c:if test="${rank.colVideoType == 4}">checked</c:if>>
                    &nbsp;综艺
                </label>
                <label>
                    <input type="radio" name="colVideoType" value="16"
                           <c:if test="${rank.colVideoType == 16}">checked</c:if>>
                    &nbsp;纪录片
                </label>
                <label>
                    <input type="radio" name="colVideoType" value="6"
                           <c:if test="${rank.colVideoType == 6}">checked</c:if>>
                    &nbsp;儿童
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">生效产品</label>
            <div class="col-sm-10">
                <c:forEach items="${products}" var="product">
                    <label class="control-label">
                        <input type="checkbox" name="enabledPro" value="${product.proNum}"
                               <c:if test="${fn:indexOf(rank.enabledPro,product.proNum)>-1 or (empty rank.id)}">checked</c:if>>
                            ${product.name}
                    </label>
                </c:forEach>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">启用平台</label>
            <div class="col-sm-10">
                <label class="control-label"> <input type="checkbox"
                                                     name="platForm" value="iphone"
                                                     <c:if test="${fn:indexOf(rank.platForm,'iphone')>-1 || create == 1}">checked</c:if>>
                    &nbsp;iphone
                </label>
                <label class="control-label"> <input type="checkbox"
                                                     name="platForm" value="ipad"
                                                     <c:if test="${fn:indexOf(rank.platForm,'ipad')>-1 || create == 1}">checked</c:if>>
                    &nbsp;ipad
                </label>

                <label class="control-label"> <input type="checkbox"
                                                     name="platForm" value="aphone"
                                                     <c:if test="${fn:indexOf(rank.platForm,'aphone')>-1 || create == 1}">checked</c:if>>
                    &nbsp;aphone
                </label>
                <label class="control-label"> <input type="checkbox"
                                                     name="platForm" value="apad"
                                                     <c:if test="${fn:indexOf(rank.platForm,'apad')>-1 || create == 1}">checked</c:if>>
                    &nbsp;apad
                </label>
                <label class="control-label"> <input type="checkbox"
                                                     name="platForm" value="atv"
                                                     <c:if test="${fn:indexOf(rank.platForm,'atv')>-1 || create == 1}">checked</c:if>>
                    &nbsp;atv
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">状态</label>
            <div class="col-sm-10">
                <label>
                    <input type="radio" name="colState" value="-1"
                           <c:if test="${rank.colState == -1 || create == 1}">checked</c:if>>
                    &nbsp;未启用
                </label>
                &nbsp;&nbsp;
                <label>
                    <input type="radio" name="colState" value="1" <c:if test="${rank.colState == 1}">checked</c:if>>
                    &nbsp;启用
                </label>
                &nbsp;&nbsp;
                <label>
                    <input type="radio" name="colState" value="3" <c:if test="${rank.colState == 3}">checked</c:if>>
                    &nbsp;审核使用
                </label>
            </div>
        </div>
    </form>
</div>

<div class="modal-footer">
    <button data-dismiss="modal" class="btn btn-default" type="button" id="cancelBtn">取消</button>
    <button class="btn btn-theme" type="button" id="saveBtn">保存</button>
</div>
<!-- modal -->
<script type="text/javascript">
    $(function () {
        $("input[name=robotFlag]:checked").click();
    });

    $("#saveBtn").bind("click", function () {
        if (!checkForm("#editForm")) {
            return;
        }
        var data = $("#editForm").serializeArray();
        var package = new AJAXPacket("${ctx}/rank/save");
        package.data.data = data;
        core.ajax.sendPacket(package, function (response) {
            if (response.data.success) {
                alertMsg.correct("成功！");
                $("#cancelBtn").click();
                jumpPageTo('_list');
            } else {
                alertMsg.error(response.data.errMsg);
            }
        });
        package = null;
    });

    function checkState(obj) {
        var robotFlag = $(obj).val();
        if (robotFlag == 1) {
            if ($("input[name=colState][value='3']").attr('checked')) {
                $("input[name=colState][value='-1']").attr('checked', 'checked');
            }
            $("input[name=colState][value='3']").attr('disabled', 'disabled');
        } else if (robotFlag == 0) {
            $("input[name=colState][value='3']").removeAttr('disabled');
        }
    }

    function checkForm(obj) {
        if ("" == $.trim($(obj).find("input[name=colName]").val())) {
            alertMsg.warn("标题不能为空！");
            $(obj).find("input[name=colName]").focus();
            return false;
        }
        if ($(obj).find('input[name=colVideoType]:checked').size() < 1) {
            alertMsg.info('请选择分类!');
            $(obj).find("input[name=colVideoType]:first").focus();
            return false;
        }
        if ($(obj).find('input[name=colState]:checked').size() < 1) {
            alertMsg.info('请选择启用状态!');
            $(obj).find("input[name=colState]:first").focus();
            return false;
        }
        return true;
    }
</script>